package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-16 16:31
 **/
public class LeetCode2140 {

    public long mostPoints(int[][] questions) {
        int n = questions.length;
        long[] dp = new long[n];
        dp[n - 1] = questions[n - 1][0];
        long max = dp[n - 1];
        for (int i = n - 2; i >= 0; --i) {
            dp[i] = Math.max(dp[i + 1], questions[i][0] + (i + questions[i][1] + 1 < n ? dp[i + questions[i][1] + 1] : 0)) ;
            max = Math.max(max, dp[i]);
        }
        return max;
    }

}
